package com.three.digit.algorithm;

import java.util.List;

import com.three.digit.model.PercentHashSet;
import com.three.digit.model.Point;
import com.three.digit.model.Tendency;

public class TendencyBeforeSumAlgorithm
{
    public PercentHashSet <Integer> doCalculate (List <Tendency> tendencies)
    {
        PercentHashSet <Integer> percentHashSet = new PercentHashSet <Integer> ();

        for (Tendency tendency : tendencies)
        {
            percentHashSet.add (sumBefore (tendency) - tendency.getCurrent ().sum ());
        }

        return percentHashSet;
    }

    private int sumBefore (Tendency tendency)
    {
        List <Point> before = tendency.getBefore ();
        int sum = 0;

        for (Point point : before)
        {
            sum += point.sum ();
        }

        return sum / before.size ();
    }
}
